package com.slimbloody.client;

import com.slimbloody.interfaces.EurekaServiceGrpc;
import com.slimbloody.interfaces.HelloReply;
import com.slimbloody.interfaces.HelloRequest;
import io.grpc.StatusRuntimeException;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

@Service
public class EurekaService {
  @GrpcClient("server-app")
  private EurekaServiceGrpc.EurekaServiceBlockingStub eurekaServiceStub;

  public String receiveGreeting(String name) {
    try {
      HelloRequest request = HelloRequest.newBuilder()
        .setName(name)
        .build();
      HelloReply helloReply = eurekaServiceStub.sayHello(request);
      return helloReply.getMessage();
    } catch (StatusRuntimeException e) {
      return "FAILED with " + e.getStatus().getCode().name();
    }
  }
}
